package day25;

/**
 * 树根
 *
 * @author wileda
 * @date 2023/04/04  9:26
 */
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()){
            String str = scanner.nextLine();
            System.out.println(Root(str));
        }
    }
    public static String Root(String str){
        String s = "";
        int count = 0;
        for(int i = 0; i < str.length(); i++){
            char ch = str.charAt(i);
            count += ch - '0';
            s = String.valueOf(count);
        }
        if(s.length() > 1){
            return Root(s);
        }
        return s;
    }
}